<!--
 * @Author: Bennty
 * @Date: 2024-07-18 10:18:27
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2024-09-12 16:54:20
 * @Description: 请填写简介
-->
<template>
    <el-dialog v-model="props.visible" width="30%" title="合同审批" @close="handleClose" destroy-on-close>
        <el-form :model="formData" ref="formRef">
            <el-form-item label="客户名称">{{ props.data.customerName }}</el-form-item>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="合同总额">{{ props.data.contractAmount }}</el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="合同定金">{{ props.data.contractDeposit }}</el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="签约时间">{{ props.data.signDate }}</el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="终止时间">{{ props.data.endDate }}</el-form-item>
                </el-col>
            </el-row>
            <el-form-item label="备注" prop="remark">
                <el-input type="textarea" maxlength="128" show-word-limit v-model="formData.remark"></el-input>
            </el-form-item>
            <el-form-item label="合同详情"></el-form-item>
            <div class="carousel-container">
                <el-carousel trigger="click" :autoplay="false">
                    <el-carousel-item  >
                        <el-image style="width: 400px; height: 565.6px" class="contract-image" :src="props.data.fileUrl" fit="fill"></el-image>
                    </el-carousel-item>
                </el-carousel>
            </div>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button  type="primary" @click="handleApprove">通过</el-button>
                <el-button type="danger" @click="handleReject">拒绝</el-button>
                <el-button @click="handleClose">取 消</el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import type { FormInstance } from 'element-plus';
import { approveContractDetailsApi } from '@/api/sj/contract-crm/index';

const props = defineProps(['visible','data']);
const emits = defineEmits(['close','submit']);
const formRef = ref<FormInstance>();
const formData = ref({
    remark: undefined
});

const handleApprove = async ()=>{
    const submitData = {...formData.value, contractId: props.data.id, type: '1', approvalStatus: '1'};
    await approveContractDetailsApi(submitData).then((result)=>{
        if(result.code == 200){
            emits('submit',true);
            handleClose();
        }else{
            emits('submit',false); 
        }
    });
};

const handleReject = async ()=>{
    const submitData = {...formData.value, contractId: props.data.id, type: '1', approvalStatus: '2'};
    await approveContractDetailsApi(submitData).then((result)=>{
        if(result.code == 200){
            emits('submit',true);
            handleClose();
        }else{
            emits('submit',false); 
        }
    });
};

const handleClose = ()=>{
    formRef.value?.resetFields();
    emits('close');
};
</script>

<style lang="scss" scoped>
.carousel-container{
    width:100%;
    display: flex;
    justify-content: center;
}
.el-carousel{
    width: 500px;
    height: calc(500px * 1.414);
    ::v-deep(.el-carousel__container){
        width: 500px;
        height: calc(500px * 1.414);
    }
}
.dialog-footer{
    display:flex;
    justify-content: center;
}
</style>